Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add reserved_account_keys module to sdk #35341

Closed

Conversation

jstarry
Copy link
Member

@jstarry jstarry commented Feb 28, 2024

Problem

No way to introduce new reserved account keys which cannot be write locked by transactions.

Summary of Changes

Add a ReservedAccountKeys module to sdk which facilitates adding feature-gated reserved account keys like new sysvars and new enshrined programs.

Note that the new module is not currently used anywhere. It's added here on its own to facilitate faster reviews over smaller patchsets of code. To see the full changes, look here: #34901

Feature Gate Issue: #34899

@jstarry jstarry added the feature-gate Pull Request adds or modifies a runtime feature gate label Feb 28, 2024
std::collections::HashSet,
};

// Temporary until a zk token program module is added to the sdk
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added separately in this PR: #35339

impl ReservedAccountKeys {
/// Compute a set of all reserved keys, regardless of if they are active or not
pub fn active_and_inactive() -> HashSet<Pubkey> {
RESERVED_ACCOUNT_KEYS
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason to prefer a singleton over making ReservedAccountKeys hold a Vec directly. then Bank can just pass an Arc around.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Bank uses an Arc wrapped HashSet. This module lives in solana-sdk because feature set is in solana-sdk but the message types live in solana-program still. So since the message types all operate over a HashSet, the Bank does so too.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the Messages referencing this list not the primary bug here? doesn't seem like something we'd want to constrain the solution by. that is, we should invert the test such that this list doesn't need to be public and can be totally encapsulated in runtime/bank

RESERVED_ACCOUNT_KEYS
.iter()
.map(|reserved_key| reserved_key.key)
.collect()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how are these used? if we instead used a HashMap (probably in conjunction with the above change), can we move whatever tests these outputs are used for internally and directly query the map instead of allocating?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's only allocated once per bank. What are the keys and values of your proposed HashMap and what does it give us over a HashSet?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of the global Vec, HashMap<Pubkey, Option<Pubkey>>. we get the HashSet-like accessors for free. no allocations other than passing the Arc on to each successor bank

Copy link

codecov bot commented Feb 28, 2024

Codecov Report

Attention: Patch coverage is 85.50725% with 10 lines in your changes are missing coverage. Please review.

Project coverage is 81.7%. Comparing base (da08868) to head (0c98be2).
Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##           master   #35341     +/-   ##
=========================================
- Coverage    81.7%    81.7%   -0.1%     
=========================================
  Files         834      835      +1     
  Lines      224244   224368    +124     
=========================================
+ Hits       183398   183459     +61     
- Misses      40846    40909     +63     

Copy link
Contributor

@t-nelson t-nelson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sry apparently i forgot to submit this the other night

impl ReservedAccountKeys {
/// Compute a set of all reserved keys, regardless of if they are active or not
pub fn active_and_inactive() -> HashSet<Pubkey> {
RESERVED_ACCOUNT_KEYS
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the Messages referencing this list not the primary bug here? doesn't seem like something we'd want to constrain the solution by. that is, we should invert the test such that this list doesn't need to be public and can be totally encapsulated in runtime/bank

RESERVED_ACCOUNT_KEYS
.iter()
.map(|reserved_key| reserved_key.key)
.collect()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of the global Vec, HashMap<Pubkey, Option<Pubkey>>. we get the HashSet-like accessors for free. no allocations other than passing the Arc on to each successor bank

@willhickey
Copy link
Contributor

This repository is no longer in use. Please re-open this pull request in the agave repo: https://github.com/anza-xyz/agave

@willhickey willhickey closed this Mar 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-gate Pull Request adds or modifies a runtime feature gate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants